import gAddForm from "./components/g-add-form.vue";
import gTable from "./components/g-table.vue";
import gTree from './components/g-tree.vue';
import iconPicker from './ModelVueIcon/iconPicker.vue';
import gCheckAll from "./components/check-all.vue";
import 'font-awesome/css/font-awesome.min.css';
import { openModel, objectFilter, sum, setAnimation, changePassword, encrypt, decrypt, downloadExcel, createForm, createTable, hasHorizontalScrollbar, hasVerticalScrollbar, openDownloadExcel, createRolePower, arrInArr } from "./components/tools";
import optimize, { throttle, debounce } from './components/optimize';
const components = [
    gAddForm, gTable, gTree, iconPicker, gCheckAll
]
// 定义 install 方法
const install = function (Vue, settings) {
    let globleBtnStyle = Object.assign({
        size: "medium", type: 'primary', plain: true, round: false, circle: false
    }, settings.globleBtnStyle);
    let funs = Object.assign({
        formFooterAlign: () => "center",
        //FORM 项标题分散对齐
        formLabelJustify: () => false,
        //FORM 显示验证错误消息
        showErrMessage: () => true,
        //================TABLE=======================
        //TABLE 上下查询风格或左右查询风格
        queryH: true,
        //TABLE 分页条显示位置letf|center|right|flex-end|flex-start
        page_align: () => 'flex-end',
        //TABLE 查询标题分散对齐
        queryLabelJustify: () => false,
        //TABLE 查询标题宽度
        queryLabelWidth: () => 100,
        //TABLE 查询输入宽度
        queryInputWidth: () => 160,
        //TABLE 表格右侧操作按钮显示位置letf|center|right|flex-end|flex-start
        controlAlign: () => 'center',
        //TABLE 表格列默认宽度 默认120px
        dWidth: () => '120px',
        //TABLE 列设置宽度
        setWidth: () => '528px',
        //用户自定义信息存储
        saveCache: (a, b) => { console.log(a, b) },
        //分页条数
        pagesize: () => 20,
        //增加时插入最前面
        insertTop: false,
        //默认双击表格行打开查看表单
        defaultDbClickFunc: "read",
        //处理排序
        handleSort: (query, col, order) => { }
    }, settings);
    let defaultBtnStyle = { size: "medium", type: "primary", plain: true, round: false, circle: false, style: undefined };
    let firstBtnStyle = Object.assign(defaultBtnStyle, settings.globleBtnStyle);
    const getItems = (key) => { if (settings && settings.btnStyle) { return settings.btnStyle[key] } else { return {} } }
    let temp = {
        save: Object.assign({ text: "保存", icon: 'el-icon-circle-check' }, firstBtnStyle, getItems('save')),
        add: Object.assign({ text: "新增", icon: 'el-icon-plus', type: "primary" }, firstBtnStyle, getItems('add')),
        del: Object.assign({ text: "删除", icon: 'el-icon-delete', }, firstBtnStyle, { type: 'text', }, getItems("del")),
        edit: Object.assign({ text: "编辑", icon: 'el-icon-edit', type: 'text', plain: false }, getItems("edit")),
        read: Object.assign({ text: "查看", icon: 'el-icon-reading', type: 'text', plain: false }, getItems("read")),
        search: Object.assign({ text: "查询", icon: 'el-icon-search' }, firstBtnStyle, getItems("search")),
        setting: Object.assign({ text: "设置列", icon: 'el-icon-setting' }, firstBtnStyle, getItems("setting")),
        close: Object.assign({ text: "关闭", icon: 'el-icon-circle-close' }, firstBtnStyle, getItems("close")),
        commit: Object.assign({ text: "提交", icon: 'el-icon-success' }, firstBtnStyle, getItems("commit")),
        cancel: Object.assign({ text: "取消", icon: 'el-icon-error' }, firstBtnStyle, getItems("cancel")),
        refresh: Object.assign({ text: "刷新", icon: 'el-icon-refresh-right' }, firstBtnStyle, getItems("refresh")),
        batch: Object.assign({ text: "批量处理", icon: 'el-icon-s-data' }, firstBtnStyle, getItems("batch")),
        more: Object.assign({ text: "更多", icon: 'el-icon-more' }, firstBtnStyle, getItems("more")),
        treeDel: Object.assign({ text: "删除", icon: 'el-icon-delete' }, firstBtnStyle, { plain: false, type: 'text' }, getItems("treeDel")),
        treeEdit: Object.assign({ text: "编辑", icon: 'el-icon-edit-outline' }, firstBtnStyle, { plain: false, type: 'text' }, getItems("treeEdit")),
        treeAdd: Object.assign({ text: "增加下级", icon: 'el-icon-circle-plus-outline' }, firstBtnStyle, { plain: false, type: 'text' }, getItems("treeAdd")),
        treeRefresh: Object.assign({ text: "刷新", icon: 'el-icon-refresh-right' }, firstBtnStyle, { plain: false, type: 'text' }, getItems("treeRefresh")),
    }
    Vue.prototype.globlSetting = Object.assign(temp, funs);
    Vue.prototype.globlSetting.globleBtnStyle = globleBtnStyle;
    if (install.installed) return
    install.installed = true
    // 遍历并注册全局组件
    components.forEach(component => Vue.component(component.name, component))
}
//  全局引用可自动安装
if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue)
}

export default {
    // 导出的对象必须具备一个 install 方法
    install,
    // 组件列表
    ...components
}
export {
    openModel, createForm, createTable, openDownloadExcel, downloadExcel, createRolePower, setAnimation, changePassword,
    sum, objectFilter, encrypt, decrypt, optimize, throttle, debounce, hasHorizontalScrollbar, hasVerticalScrollbar, arrInArr
}




